package ru.nosport.matrixaria.modules.user.rexample.server;

import ru.nosport.matrixaria.modules.common.AppServerProcess;
import ru.nosport.matrixaria.core.MLogger;
import org.apache.commons.configuration.Configuration;

import java.util.logging.Level;

/**
 * User: Victor Fabrichenko
 * Date: 24.12.2008
 * Time: 14:25:51
 */
public class RemoteServerApp implements AppServerProcess, RemoteServer{
	private Configuration conf;
	private DataContainer[] dc200;

	public RemoteServerApp(Configuration _conf){
		this.conf = _conf;

		this.dc200 = new DataContainer[200000];

		Integer vInt = this.conf.getInt("integer");
		Long vLong = this.conf.getLong("long");
		Double vDouble = this.conf.getDouble("double");
		Float vFloat = this.conf.getFloat("float");
		Boolean vBool = this.conf.getBoolean("boolean");
		String vString = this.conf.getString("string");

		Long start = System.currentTimeMillis();

		for(Integer i = 0; i < 200000; i++){
			this.dc200[i] = new DataContainer(vInt, vBool, vLong, vFloat, vDouble, vString + i);
		}
	}

	public boolean moduleStart() throws Exception {
		return true;
	}

	public boolean moduleStop() {
		return true;
	}

	public boolean isModuleRunning() {
		return true;
	}

	public String moduleStat() {
		return "RemoteServerApp stat";
	}

	public DataContainer getDataContainer(String _key) {
		Integer vInt = this.conf.getInt("integer");
		Long vLong = this.conf.getLong("long");
		Double vDouble = this.conf.getDouble("double");
		Float vFloat = this.conf.getFloat("float");
		Boolean vBool = this.conf.getBoolean("boolean");

		DataContainer data = new DataContainer(vInt, vBool, vLong, vFloat, vDouble, _key);
		return data;
	}

	public DataContainer[] getDataContainerList(Integer _count) {
		if(_count == 200000){
			return this.dc200;
		}

		DataContainer[] rez = new DataContainer[_count];

		Integer vInt = this.conf.getInt("integer");
		Long vLong = this.conf.getLong("long");
		Double vDouble = this.conf.getDouble("double");
		Float vFloat = this.conf.getFloat("float");
		Boolean vBool = this.conf.getBoolean("boolean");
		String vString = this.conf.getString("string");

		Long start = System.currentTimeMillis();

		for(Integer i = 0; i < _count; i++){
			rez[i] = new DataContainer(vInt, vBool, vLong, vFloat, vDouble, vString + i); 
		}

		Long stop = System.currentTimeMillis();

		System.out.println(rez.length+" list creatred. time ["+(stop - start)+"]");
		//MLogger.get(this).log(Level.INFO, rez.length+" list creatred. time ["+(stop - start)+"]");

		return rez;
	}
}
